tiny-c shell.html - lrb - 1/27/10

Source: pp 91-93 of Scott B. Guthery's book "Learning C with tiny-c" 1985 TAB Books Inc.

The tiny-c shell is a program editor and launcher. It is a great example of a tiny-c program in its own right. I usually use a full screen editor to build tiny-c programs but it's worth learning how to use the tiny-c shell's line editor as well.

All the commands below must be preceded by a period (.) when they are entered at the tc> prompt. For example

tc>.d 5

would delete 5 lines of your program text starting at the current line.

If you do not type a period as the first character, what you type is inserted into your tiny-c program text. If you do type a period but what follows the period is not a shell command, for example, .foobar, the interpreter assumes you are trying to launch a function named foobar that is in a system library or your program text.

Besides "collect mode," tiny-c can be used in "immediate" mode.

tc>.pn 1+1

would display the number 2. tiny-c is a calculator!

tc>.[char c;for (c='a';c<='z';++c)[putchar(c)]]

would display the lowercase alphabet. Note the need for brackets. "Immediate mode" is often very useful during the debugging phase.

Finally, before documenting the individual editor commands, we should mention errors. Quoting Scott Guthery:

"Sometimes ... just sometimes ... when you run a tiny-c program an error will be detected. When this happens, the program halts and the shell resumes control of the situation. Your program text is intact; you can edit it or restart it or write it to a disc.

The shell prints three lines of helpful information about what happened and then gives you its prompt:

17 -- err 26
text of bad line
      <
tc>

The first line shows the line number on which the error occurred and the error number."

tiny-c error codes are documented at tiny-c error codes.

tiny-c shell commands

Command Arguments

.c/string-1/string-2/

Action:

Replace (Change) string-1 with string-2 in the current line; the slash
(/) can be any character not appearing in string-1 or string-2.

Default:

If no arguments are given, the previous change command is repeated.

Command Arguments

.d n

Action:

Delete n lines, starting at the current line. Default:	If not given, n
is taken to be 1.

Command Arguments

.l/string/

Action:

The program text is searched forward (located) starting at the current
line for the first appearance of string; the slash (/) may be any
character not appearing in string.

Default:

If no argument is given, the previous locate command is repeated.

Command Arguments

.p n

Action:

Print n lines starting with the current line. Default: If not given, n
is taken to be 1.

Command Arguments

.r filename

Action:

The contents of the file named filename are appended to the end of the
program text.

Command Arguments

.w filename

Action:

The contents of the program text area are written to the file named filename.

Command Arguments

.x

Action:

tiny-c exits and return to the DOS or Linux terminal prompt.

Command Arguments

+n

Action:

The current line number is incremented by n.

Default:

If not given, n is taken to be 1.

Command Arguments

-n

Action:

The current line number is decremented by n.

Default:

If not given, n is taken to be 1.

Command Arguments

./

Action:

Prints the current line number, the total number of lines, the total
number of characters used and the total number of characters unused.